package com.mz.mattress.api.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class MathUtil {

    public static final BigDecimal HUNDRED = new BigDecimal(100);

    public static final BigDecimal THOUSAND = new BigDecimal(1000);

    public static final int toFen(String val) {
        BigDecimal dd = new BigDecimal(val).multiply(HUNDRED);
        return dd.intValue();
    }

    public static final Integer discount(Integer total, Integer discount) {
        BigDecimal dd = new BigDecimal(total).multiply(new BigDecimal(discount).divide(HUNDRED));
        return dd.intValue();
    }

    //微信手续费
    public static final Integer wxFee(Integer total) {
        BigDecimal dd = new BigDecimal(total).multiply(new BigDecimal(6).divide(THOUSAND));
        return dd.intValue();
    }

    public static final Integer divide(Integer total, Integer count) {
        BigDecimal dd = BigDecimal.valueOf(total)
                .divide(BigDecimal.valueOf(count), 0, RoundingMode.HALF_UP);
        return dd.intValue();
    }

    public static final Integer toFen(BigDecimal val) {
        if (val == null) {
            return null;
        }
        BigDecimal dd = val.multiply(HUNDRED);
        return dd.intValue();
    }

    public static void main(String[] args) {
        Integer divide = MathUtil.divide(35800, 6);
        System.out.println(divide);

    }

}
